
YWC.uri.cdn = YWC.uri.pre;

YWC.track.google.appId = "UA-26875993-2";
YWC.track.mixpanel.appId = "e823f3111903e5f4bd171a0d5afb5b84";
YWC.track.mixpanel.meta.identify = "";
YWC.track.mixpanel.meta.name_tag = "";

YWC.popup.xColor = "a60016";
YWC.popup.xBgColor = "ffffff";
YWC.popup.brdrColor = "888888";
YWC.popup.brdrRadius = 5;
//YWC.popup.marginWidth = 20;
YWC.popup.anchorMargin = 15;
YWC.popup.anchorArrowToggle = true;
YWC.popup.xWidth = 45;
YWC.popup.xOffset = 12;
YWC.popup.xType = "circle";
YWC.popup.brdrWidth = 1;

YWC.input.meta.dateTime[0].format['12h'] = false;
YWC.input.meta.dateTime[0].format['date'] = "yy-mm-dd";

YWC.ui.jQueryUI.themeUri = "lib/oist/1.0/css/jquery-ui/1.8.22/jquery-ui.custom.css";

YWC.intranet.authCheckToggle = true;

YWC.intranet.uiHeaderColor = 'c70019';
YWC.intranet.uiHeaderBgColor = 'c9c0bb';
YWC.intranet.uiFallbackImage = '//www.oist.jp/sites/default/files/img/workshops/cluster2012/oist-logo_800x800.jpg';

YWC.intranet.uriSubmitPost = 'bws/action/ywc_';
//YWC.intranet.methodSubmitPost = "POST";
//YWC.intranet.dataTypeSubmitPost = "json";

YWC.intranet.uriDeletePost = YWC.uri.pre+'bws/action/ywc_';
YWC.intranet.methodDeletePost = "DELETE";
YWC.intranet.dataTypeDeletePost = "json";

YWC.intranet.autoRefreshLists = ["announcements","marketplace","community","events","news-external"];

var OIST = {'f':{}};


OIST.f.assetListPaging = function(listId) {
	
	$.ajax({ type:"POST", dataType:"script", url:YWC.uri.pre+'tida/data/asset', data:{
			'listName':listId, 'sortBy':'@ows_ID'
			,'groupCurr':YWC.list.meta[listId].groupCurr
			,'groupSize':YWC.list.meta[listId].groupSize
			,'searchTerm':YWC.f.assetSearchTerm(listId)
		}, success: function() {
			YWC.f.assetDrawList(listId,false,false);
		}
	});
}

OIST.f.popupEmergencyInfo = function(anchorObj) {
	
	YWC.f.popupLoad({
		'width':500,'top':-20,'anchorOn':'left','anchorObj':anchorObj
		,'z':1,'dragEnabled':false
		,'source':'<div id="oist-emergency-info">'
			+'<img class="ywc-asset-list-loading ywc-unselectable ywc-trans-0 ywc-trans-0"'
			+' onLoad="YWC.f.uiItemFadeIn(this)"'
			+' src="'+YWC.uri.pre+'lib/ywc-image/1.0/anim/spin-01.gif" />'
			+'</div>'
		,'id':'oist-emergency-info'
		,'callback':function(){
			$("div#oist-emergency-info").load(YWC.uri.pre+"url/www.oist.jp/node/6571 section#main-content");
		}
	});
}

	
YWC.f.intranetPostSubmit = function(listName,assetId,cacheId) {
	
	var vals = YWC.input.value;
	
	var params = {'ywc_cache_id':cacheId};
	params.title = vals.text[listName+'-title'];
	
	if (vals.text[listName+'-body'] != null) {
		params["body[und][0][value]"] = vals.text[listName+'-body'];
		params["body[und][0][format]"] = 'full_html';
	}
	
	if (vals.datetime[listName+'-expires'] != null) {
		params["field_ywc_expires[und][0][value]"] = Math.round(vals.datetime[listName+'-expires']/1000);
	}
	
	if (vals.hidden[listName+'-author'] != null) {
		params["field_ywc_author[und][0][value]"] = vals.hidden[listName+'-author'];
	}
		
	if (vals.file[listName+'-upload'] != null) {
		params["field_ywc_attachments[und][0][value]"] = JSON.stringify(vals.file[listName+'-upload']);
	}	
	
	if (vals.checkbox[listName+'-category'] != null) {
		params["field_ywc_"+listName+"_category[und][value]"] = vals.checkbox[listName+'-category'];
	}

	if (vals.checkbox[listName+'-type'] != null) {
		params["field_ywc_"+listName+"_type[und][value]"] = vals.checkbox[listName+'-type'];
		params["field_ywc_posting_type[und][value]"] = vals.checkbox[listName+'-type'];
	}

	if (vals.select[listName+'-category'] != null) {
		params["field_ywc_"+listName+"_category[und][value]"] = vals.select[listName+'-category'];
		params["field_ywc_posting_category[und][value]"] = vals.select[listName+'-category'];
	}	

	if (vals.text[listName+'-price'] != null) {
		params["field_ywc_price[und][0][value]"] = vals.text[listName+'-price'];
	}
	
	if (vals.text[listName+'-location'] != null) {
		params["field_ywc_location[und][0][value]"] = vals.text[listName+'-location'];
	}

	if (vals.datetime[listName+'-start'] != null) {
		params["field_ywc_start_datetime[und][0][value]"] = Math.round(vals.datetime[listName+'-start']/1000);
	}
	
	if (vals.datetime[listName+'-end'] != null) {
		var duration = Math.round((vals.datetime[listName+'-end']-vals.datetime[listName+'-start'])/1000);
		if (duration < 0) { duration = 0; }
		params["field_ywc_duration[und][0][value]"] = duration;
	}
	
	var submitUri = YWC.intranet.uriSubmitPost;
	if (submitUri.indexOf('bws/') > -1) {
		submitUri = submitUri+listName;
		if (assetId != '') { submitUri = submitUri+'/'+assetId; }
	}
	
	if (	(params.title == "")
		||	(params.author == "")
	) {
		
		YWC.f.intranetPostSubmitError(listName,'Some mandatory fields were not filled.');
		
	} else {
	
		$.ajax({ type:YWC.intranet.methodSubmitPost
			,dataType: YWC.intranet.dataTypeSubmitPost
			,url:YWC.uri.pre+submitUri
			,data: params
			,beforeSend: function(){ YWC.f.intranetPostSubmitBeforeSend(listName); }
			,complete: function() {	YWC.f.intranetPostSubmitComplete(listName); }
			,success: function() { YWC.f.intranetPostSubmitSuccess(listName); }
			,error: function() { YWC.f.intranetPostSubmitError(listName); }
		});
	}
}




$(function(){
	
	YWC.f.intranetAutoRefresh();
	
});

